import 'package:city_pickers/city_pickers.dart';
import 'package:city_pickers/modal/result.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:shenfuhui/config/config.dart';
import 'package:shenfuhui/tabview/mall_home_classify.dart';
import 'package:shenfuhui/views/search_appbar.dart';

import '../routers/routers.dart';
import '../tabview/mall_home_index.dart';
import '../tabview/mall_home_products.dart';
import '../views/dialog_manager.dart';

///
/// 店铺首页
///
class MallHomePage extends StatefulWidget {
  const MallHomePage({Key? key}) : super(key: key);

  @override
  State<MallHomePage> createState() => _MallHomePageState();
}

class _MallHomePageState extends State<MallHomePage> {
  List<TabItem> tabItems = [
    const TabItem(icon: Icons.local_mall_outlined, title: '店铺首页'),
    const TabItem(icon: Icons.list_alt_outlined, title: '全部商品'),
    const TabItem(icon: Icons.category_outlined, title: '商品分类'),
  ];

  List<Widget> tabViews = [
    const MallHomeIndexPage(),
    const MallHomeProductsPage(),
    const MallHomeClassifyPage(),
  ];

  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      appBar: AppBar(
        title: SearchAppBar(
          hintLabel: '请输入商品名称',
          callBack: () {},
        ),
        centerTitle: true,
      ),
      bottomNavigationBar: ConvexAppBar(
        items: tabItems,
        backgroundColor: Config.colorWhite,
        color: Config.colorText3,
        activeColor: Config.colorMain,
        style: TabStyle.reactCircle,
        elevation: 5.w,
        top: -15,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Stack(
          children: [
            Container(
              height: 140.w,
              decoration: BoxDecoration(
                  color: Config.colorWhite,
                  borderRadius: BorderRadius.circular(12.w)),
              margin: EdgeInsets.symmetric(horizontal: 20.w, vertical: 20.w),
              child: InkWell(
                onTap: () {},
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      margin: EdgeInsets.only(left: 20.w, right: 20.w),
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(5),
                        child: Image.network(
                          "https://pic1.zhimg.com/v2-6438843a4cbae9184b935a75a5059ac6_1440w.jpg?source=172ae18b",
                          fit: BoxFit.fill,
                          width: 100.w,
                          height: 100.w,
                        ),
                      ),
                    ),
                    Container(
                      height: 110.w,
                      width: 430.w,
                      child: Stack(
                        children: [
                          InkWell(
                            onTap: () {},
                            child: Row(
                              children: [
                                Text(
                                  "商家名称",
                                  softWrap: true,
                                  maxLines: 2,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(
                                      color: (Config.colorText1),
                                      fontSize: 26.w),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(left: 10.w),
                                ),
                                Icon(
                                  Icons.headset_mic,
                                  size: 30.w,
                                  color: Config.colorMain,
                                ),
                              ],
                            ),
                          ),
                          Positioned(
                            bottom: 8.w,
                            child: Row(
                              children: [
                                Container(
                                  decoration: BoxDecoration(
                                    color: Config.colorMain,
                                    borderRadius: BorderRadius.circular(20.w),
                                  ),
                                  padding: EdgeInsets.symmetric(
                                      vertical: 3.w, horizontal: 10.w),
                                  margin: EdgeInsets.only(left: 1.w),
                                  child: Text(
                                    "综合评分 5.0",
                                    style: TextStyle(
                                        fontSize: 16.sp,
                                        color: Config.colorWhite),
                                  ),
                                ),
                                Container(
                                  decoration: BoxDecoration(
                                    color: Config.colorMain,
                                    borderRadius: BorderRadius.circular(20.w),
                                  ),
                                  padding: EdgeInsets.symmetric(
                                      vertical: 3.w, horizontal: 10.w),
                                  margin: EdgeInsets.only(left: 15.w),
                                  child: Text(
                                    "999人关注",
                                    style: TextStyle(
                                        fontSize: 16.sp,
                                        color: Config.colorWhite),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 0.w),
                      width: 110.w,
                      height: 46.w,
                      child: ElevatedButton(
                        clipBehavior: Clip.antiAlias,
                        onPressed: () => {
                          // Routes.router.navigateTo(context, Routes.mineAddressEdit,
                          //     transition: TransitionType.inFromRight)
                        },
                        style: ButtonStyle(
                          elevation: MaterialStateProperty.all(0),
                          backgroundColor:
                              MaterialStateProperty.all(Colors.white),
                          shape: MaterialStateProperty.all(
                            RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(24.w),
                            ),
                          ),
                          side: MaterialStateProperty.all(
                            BorderSide(color: Config.colorText3, width: 2.w),
                          ),
                        ),
                        child: Text(
                          '收藏',
                          style: TextStyle(
                              fontSize: 18.sp, color: Config.colorText3),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              height: double.infinity,
              // decoration: BoxDecoration(
              //   color: Config.colorWhite,
              //   borderRadius: BorderRadius.circular(12.w),
              // ),
              margin: EdgeInsets.only(top: 180.w, left: 20.w, right: 20.w,bottom: 15.w),
              child: IndexedStack(
                index: _currentIndex,
                children: tabViews,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
